#!/bin/python
import sys,os;

class ThInfo:
	def __init__(self):
		self.pvth = 0;
		self.uvth = 0;
		self.relth = 0;

	def __init__(self, items):
		self.pvth = int(items[1]);
		self.uvth = int(items[2]);
		self.relth = float(items[3]);

TH={};
#input file format: relscore url pv uv title content
if __name__ == "__main__":
	inputfile = sys.argv[1];
	thfile = sys.argv[2];
	category = sys.argv[3];
	
	#load thfile
	thf = open(thfile, 'r');
	for line in thf:
		if line[0] == '#':
			continue;
		items = line.rstrip('\r\n').split('\t');
		if len(items) != 5:
			sys.stderr.write("ERROR LINE:%s" % line)
			sys.exit(-1)
		TH[items[0]] = ThInfo(items);

	#url pv uv title content
	file = open(inputfile, 'r');
	for line in file:
		items = line.rstrip('\r\n').split("\t");

		if len(items) != 6 or items[1] == "error":
			sys.stderr.write("ERROR LINE: %s" % line)
			continue;
		rel = float(items[0]);	#items[1] is url
		url = items[1];
		pv = int(items[2]);
		uv = int(items[3]);
		if len(url) >= 200:
			continue
		if category in TH:
			if pv >= TH[category].pvth and uv >= TH[category].uvth and rel >= TH[category].relth:
				print line,
		else:
			if pv >= TH["default"].pvth and uv >= TH["default"].uvth and rel >= TH["default"].relth:
				print line,

	file.close();